let collect = $("#div-box-data");
let collect_data;


$(function () {
    personageData();
})


let collect_method = () => {
    if (collect_data != undefined) {
        collect.html(avatarData(collect_data));
    } else {
        $.modal.alertError('您还没有登入，请先登入^_^...');
    }
}

let personageData = () => {
    $.operate.request(personage_url.prefix + '/' + personage_url.personage_data, null, function (row) {
        /*关闭遮罩层*/
        $.modal.closeLoading();

        let user = row.user;

        let collectData = row.collectData;

        if (user != null && user != '' && user != undefined) {

            $(".right-img div,.article-1-box div").css("display", "none");

            $(".right-img img,.article-1-box img")
                .css("display", "block")
                .attr("src", user.avatar);
            $("#user-name").css("display", "block").text(user.userName)


        }
        if (collectData != null && collectData != '' && collectData != undefined) {
            collect.html(avatarData(collectData));
            collect_data = collectData;
            return;
        }

        if (row.code === 1) {
            collect.html(null_html_method(row.msg));

        } else if (row.code === 2) {
            collect.html(null_html_method(row.msg));

        } else {
            $.modal.alertError(row.msg);
        }

    });
}

let null_html_method = (str) => {
    return `<div class="div-usernull">
                     <img src="/img/user-null.png" style="width: 100%;height: 100%;">
                     <br>
                     <span>${str}</span>
                </div>`;
}

/*收藏数据拼接*/
let avatarData = (list) => {
    let html = '<div class="articl-1-2">';
    for (let i = 0, len = list.length; i < len; i++) {
        let author = list[i].author;
        if (author.length > 5) {
            author = author.substring(0, 5) + "..";
        }
        html += `<div class="articl-1-2-box">
                              <a href="/manhua/look/over/${list[i].id}" target="_blank">
                                  <img src="${$.haHa.decode(list[i].theCover)}" alt="${list[i].name}" onerror="$.common.errorimg(this)">
                                  <div>
                                      <span class="articl-1-2-box-left">${author}</span>
                                      <span class="articl-1-2-box-right">${list[i].reading}</span>
                                  </div>
                                  <span>${list[i].name}</span>
                              </a>
                          </div>`;
    }
    html += '</div>';
    return html;
}
